using System;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using PluginFrame;

namespace PcrExperimentProject
{
	public class FormProjectEncryption : Form
	{
		private IContainer components;

		private CheckBox chkProgram;

		private GroupBox grpPassword;

		protected Panel panelButtons;

		protected Label label2;

		protected Button btnClose;

		protected Button btnConfirm;

		private TextBox txtRePassword;

		private TextBox txtPassword;

		private Label label3;

		private Label lblPassword;

		private GroupBox grpSetEncryption;

		private CheckBox chkCrosstalk;

		private CheckBox chkAnalysisParameter;

		private CheckBox chkRule;

		private CheckBox chkOption;

		protected IPcrExperimentProject mProject;

		private string mPassword;

		protected ResourceManager mResourceManager;

		protected CheckBox[] mZoneCheckBox;

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PcrExperimentProject.FormProjectEncryption));
			this.chkProgram = new System.Windows.Forms.CheckBox();
			this.grpPassword = new System.Windows.Forms.GroupBox();
			this.txtRePassword = new System.Windows.Forms.TextBox();
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.lblPassword = new System.Windows.Forms.Label();
			this.panelButtons = new System.Windows.Forms.Panel();
			this.label2 = new System.Windows.Forms.Label();
			this.btnClose = new System.Windows.Forms.Button();
			this.btnConfirm = new System.Windows.Forms.Button();
			this.grpSetEncryption = new System.Windows.Forms.GroupBox();
			this.chkOption = new System.Windows.Forms.CheckBox();
			this.chkRule = new System.Windows.Forms.CheckBox();
			this.chkCrosstalk = new System.Windows.Forms.CheckBox();
			this.chkAnalysisParameter = new System.Windows.Forms.CheckBox();
			this.grpPassword.SuspendLayout();
			this.panelButtons.SuspendLayout();
			this.grpSetEncryption.SuspendLayout();
			base.SuspendLayout();
			this.chkProgram.AccessibleDescription = null;
			this.chkProgram.AccessibleName = null;
			resources.ApplyResources(this.chkProgram, "chkProgram");
			this.chkProgram.BackgroundImage = null;
			this.chkProgram.Name = "chkProgram";
			this.chkProgram.UseVisualStyleBackColor = true;
			this.chkProgram.CheckedChanged += new System.EventHandler(chkSetPassword_CheckedChanged);
			this.grpPassword.AccessibleDescription = null;
			this.grpPassword.AccessibleName = null;
			resources.ApplyResources(this.grpPassword, "grpPassword");
			this.grpPassword.BackgroundImage = null;
			this.grpPassword.Controls.Add(this.txtRePassword);
			this.grpPassword.Controls.Add(this.txtPassword);
			this.grpPassword.Controls.Add(this.label3);
			this.grpPassword.Controls.Add(this.lblPassword);
			this.grpPassword.Font = null;
			this.grpPassword.Name = "grpPassword";
			this.grpPassword.TabStop = false;
			this.txtRePassword.AccessibleDescription = null;
			this.txtRePassword.AccessibleName = null;
			resources.ApplyResources(this.txtRePassword, "txtRePassword");
			this.txtRePassword.BackgroundImage = null;
			this.txtRePassword.Font = null;
			this.txtRePassword.Name = "txtRePassword";
			this.txtPassword.AccessibleDescription = null;
			this.txtPassword.AccessibleName = null;
			resources.ApplyResources(this.txtPassword, "txtPassword");
			this.txtPassword.BackgroundImage = null;
			this.txtPassword.Font = null;
			this.txtPassword.Name = "txtPassword";
			this.label3.AccessibleDescription = null;
			this.label3.AccessibleName = null;
			resources.ApplyResources(this.label3, "label3");
			this.label3.Font = null;
			this.label3.Name = "label3";
			this.lblPassword.AccessibleDescription = null;
			this.lblPassword.AccessibleName = null;
			resources.ApplyResources(this.lblPassword, "lblPassword");
			this.lblPassword.Font = null;
			this.lblPassword.Name = "lblPassword";
			this.panelButtons.AccessibleDescription = null;
			this.panelButtons.AccessibleName = null;
			resources.ApplyResources(this.panelButtons, "panelButtons");
			this.panelButtons.BackgroundImage = null;
			this.panelButtons.Controls.Add(this.label2);
			this.panelButtons.Controls.Add(this.btnClose);
			this.panelButtons.Controls.Add(this.btnConfirm);
			this.panelButtons.Font = null;
			this.panelButtons.ForeColor = System.Drawing.SystemColors.ControlText;
			this.panelButtons.Name = "panelButtons";
			this.label2.AccessibleDescription = null;
			this.label2.AccessibleName = null;
			resources.ApplyResources(this.label2, "label2");
			this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.label2.Font = null;
			this.label2.Name = "label2";
			this.btnClose.AccessibleDescription = null;
			this.btnClose.AccessibleName = null;
			resources.ApplyResources(this.btnClose, "btnClose");
			this.btnClose.BackgroundImage = null;
			this.btnClose.Font = null;
			this.btnClose.Name = "btnClose";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new System.EventHandler(btnClose_Click);
			this.btnConfirm.AccessibleDescription = null;
			this.btnConfirm.AccessibleName = null;
			resources.ApplyResources(this.btnConfirm, "btnConfirm");
			this.btnConfirm.BackgroundImage = null;
			this.btnConfirm.Font = null;
			this.btnConfirm.Name = "btnConfirm";
			this.btnConfirm.UseVisualStyleBackColor = true;
			this.btnConfirm.Click += new System.EventHandler(btnConfirm_Click);
			this.grpSetEncryption.AccessibleDescription = null;
			this.grpSetEncryption.AccessibleName = null;
			resources.ApplyResources(this.grpSetEncryption, "grpSetEncryption");
			this.grpSetEncryption.BackgroundImage = null;
			this.grpSetEncryption.Controls.Add(this.chkOption);
			this.grpSetEncryption.Controls.Add(this.chkRule);
			this.grpSetEncryption.Controls.Add(this.chkCrosstalk);
			this.grpSetEncryption.Controls.Add(this.chkAnalysisParameter);
			this.grpSetEncryption.Controls.Add(this.chkProgram);
			this.grpSetEncryption.Font = null;
			this.grpSetEncryption.Name = "grpSetEncryption";
			this.grpSetEncryption.TabStop = false;
			this.chkOption.AccessibleDescription = null;
			this.chkOption.AccessibleName = null;
			resources.ApplyResources(this.chkOption, "chkOption");
			this.chkOption.BackgroundImage = null;
			this.chkOption.Font = null;
			this.chkOption.Name = "chkOption";
			this.chkOption.UseVisualStyleBackColor = true;
			this.chkRule.AccessibleDescription = null;
			this.chkRule.AccessibleName = null;
			resources.ApplyResources(this.chkRule, "chkRule");
			this.chkRule.BackgroundImage = null;
			this.chkRule.Font = null;
			this.chkRule.Name = "chkRule";
			this.chkRule.UseVisualStyleBackColor = true;
			this.chkCrosstalk.AccessibleDescription = null;
			this.chkCrosstalk.AccessibleName = null;
			resources.ApplyResources(this.chkCrosstalk, "chkCrosstalk");
			this.chkCrosstalk.BackgroundImage = null;
			this.chkCrosstalk.Font = null;
			this.chkCrosstalk.Name = "chkCrosstalk";
			this.chkCrosstalk.UseVisualStyleBackColor = true;
			this.chkAnalysisParameter.AccessibleDescription = null;
			this.chkAnalysisParameter.AccessibleName = null;
			resources.ApplyResources(this.chkAnalysisParameter, "chkAnalysisParameter");
			this.chkAnalysisParameter.BackgroundImage = null;
			this.chkAnalysisParameter.Font = null;
			this.chkAnalysisParameter.Name = "chkAnalysisParameter";
			this.chkAnalysisParameter.UseVisualStyleBackColor = true;
			base.AccessibleDescription = null;
			base.AccessibleName = null;
			resources.ApplyResources(this, "$this");
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.BackgroundImage = null;
			base.Controls.Add(this.grpSetEncryption);
			base.Controls.Add(this.panelButtons);
			base.Controls.Add(this.grpPassword);
			this.Font = null;
			base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			base.Icon = null;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "FormProjectEncryption";
			base.ShowIcon = false;
			base.ShowInTaskbar = false;
			base.Load += new System.EventHandler(FormEncryption_Load);
			base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormEncryption_FormClosing);
			this.grpPassword.ResumeLayout(false);
			this.grpPassword.PerformLayout();
			this.panelButtons.ResumeLayout(false);
			this.grpSetEncryption.ResumeLayout(false);
			this.grpSetEncryption.PerformLayout();
			base.ResumeLayout(false);
		}

		public FormProjectEncryption(IPcrExperimentProject project, IApplication application)
		{
			InitializeComponent();
			mProject = project;
			mResourceManager = ResourceManager.CreateFileBasedResourceManager("PcrExperimentProject", application.GetResourceFolder() + GetType().Namespace + "\\", null);
			if (mProject.ZonePasswordStatus == null)
			{
				mProject.ZonePasswordStatus = new bool[Enum.GetNames(typeof(ProjectPasswordEnum)).Length];
				mProject.Password = string.Empty;
				mProject.IsPasswordMatch = false;
			}
			mZoneCheckBox = new CheckBox[mProject.ZonePasswordStatus.Length];
			mZoneCheckBox[0] = chkProgram;
			mZoneCheckBox[1] = chkAnalysisParameter;
			mZoneCheckBox[2] = chkRule;
			mZoneCheckBox[3] = chkCrosstalk;
			mZoneCheckBox[4] = chkOption;
			InitializeForm();
			base.DialogResult = DialogResult.Cancel;
		}

		public string GetPassword()
		{
			if (chkProgram.Checked)
			{
				return txtPassword.Text.Trim();
			}
			return string.Empty;
		}

		private void InitializeForm()
		{
			bool inputPasswordEnabled = false;
			for (int i = 0; i < mProject.ZonePasswordStatus.Length; i++)
			{
				mZoneCheckBox[i].Checked = mProject.ZonePasswordStatus[i];
				mZoneCheckBox[i].CheckedChanged += chkSetPassword_CheckedChanged;
				if (mZoneCheckBox[i].Checked)
				{
					inputPasswordEnabled = true;
				}
			}
			SetInputPasswordEnabled(inputPasswordEnabled);
			txtRePassword.Text = string.Empty;
		}

		private void SetInputPasswordEnabled(bool isEnabledZone)
		{
			if (isEnabledZone)
			{
				grpPassword.Enabled = true;
				txtPassword.Text = mProject.Password;
			}
			else
			{
				grpPassword.Enabled = false;
				txtPassword.Text = string.Empty;
				mProject.Password = string.Empty;
			}
		}

		private bool CheckPassword()
		{
			bool flag = false;
			for (int i = 0; i < mZoneCheckBox.Length; i++)
			{
				if (mZoneCheckBox[i].Checked)
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				txtPassword.Text = txtPassword.Text.Trim();
				if (txtPassword.Text.Length < 6)
				{
					MessageBox.Show(mResourceManager.GetString("LengthofPassword"), mResourceManager.GetString("ErrorString"));
					txtPassword.Focus();
					return false;
				}
				txtRePassword.Text = txtRePassword.Text.Trim();
				if (!txtPassword.Text.Equals(txtRePassword.Text))
				{
					MessageBox.Show(mResourceManager.GetString("TwopasswordsNotMatch"), mResourceManager.GetString("ErrorString"));
					txtPassword.Text = string.Empty;
					txtRePassword.Text = string.Empty;
					txtPassword.Focus();
					return false;
				}
				for (int j = 0; j < mZoneCheckBox.Length; j++)
				{
					mProject.ZonePasswordStatus[j] = mZoneCheckBox[j].Checked;
				}
				mProject.Password = txtPassword.Text;
			}
			else
			{
				mProject.Password = string.Empty;
				for (int k = 0; k < mProject.ZonePasswordStatus.Length; k++)
				{
					mProject.ZonePasswordStatus[k] = false;
				}
			}
			return true;
		}

		private void FormEncryption_Load(object sender, EventArgs e)
		{
		}

		private void chkSetPassword_CheckedChanged(object sender, EventArgs e)
		{
			CheckBox checkBox = sender as CheckBox;
			if (checkBox == null)
			{
				return;
			}
			if (checkBox.Checked)
			{
				grpPassword.Enabled = true;
				return;
			}
			bool flag = false;
			for (int i = 0; i < mZoneCheckBox.Length; i++)
			{
				if (mZoneCheckBox[i].Checked)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				grpPassword.Enabled = false;
			}
		}

		private void btnConfirm_Click(object sender, EventArgs e)
		{
			if (CheckPassword())
			{
				base.DialogResult = DialogResult.OK;
				Close();
			}
		}

		private void FormEncryption_FormClosing(object sender, FormClosingEventArgs e)
		{
		}

		private void btnClose_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}
